using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Web.Core;
using Web.Core.Objects;

public partial class AdminCP_Contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Language"] == null)
            Session["Language"] = Web.Core.GlobalStorage.Language.English;

        int page = 1;
        if (Request.Params["page"] != null)
            page = int.Parse(Request.Params["page"]);
        ArrayList arrContact = Contacts.GetAllContactsByPage(page, 10);

        if (!IsPostBack)
        {
            this.rptContact.DataSource = arrContact;
            this.rptContact.DataBind();
        }
        // Pager
        this.Pager1.objectsPerPage = 10;
        this.Pager1.displayAll = false; // Chi hien thi ben phai
        this.Pager1.totalObjects = Contacts.CountAllContact();
        // ---------------

        if (Request.Params["do"] != null)
        {
            string pDo = Request.Params["do"];
            switch (pDo.ToLower())
            {
                case "del":
                    if (Request.Params["cid"] != null)
                    {
                        int cID = 0;
                        try
                        {
                            cID = int.Parse(Request.Params["cid"].ToString());
                        }
                        catch { }
                        Contacts.DeleteContact(Contacts.GetContactByID(cID));
                        this.PreRenderComplete += new EventHandler(AdminCP_Contact_PreRenderComplete);
                    }
                    break;
                default:
                    break;
            }
        }
    }

    void AdminCP_Contact_PreRenderComplete(object sender, EventArgs e)
    {
        Response.Redirect("Contact.aspx");
    }
}
